﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using K2CoreLib.DataObject;
using System.Data;
using K2CoreLib.Shared;

namespace K2CoreLib.Dao.Sys
{
    class MailDao
    {
        public MailTemplateDTO GetMailWithSignature(string mailcode, string signature)
        {
            string storeName = @"SYS_spGetMailTemplate";
            object[] parms = { "@MailCode", mailcode,
                                "@SignatureCode", signature }; 

            return SysDb.ReadFromStore(storeName, Make, parms);
        }


        private Func<IDataReader, MailTemplateDTO> Make = reader =>
            new MailTemplateDTO
            {
                ContentEN = reader["ContentEN"].AsString(),
                ContentVN = reader["ContentVN"].AsString(),
                CreatedDate = reader["CreatedDate"].AsDateTime(),
                CreatedUser = reader["CreatedUser"].AsString(),
                IsDeleted = reader["IsDeleted"].AsInt(),
                IsReferenced = reader["IsReferenced"].AsBool(),
                LastUpdatedDate = reader["LastUpdatedDate"].AsDateTime(),
                LastUpdatedUser = reader["LastUpdatedUser"].AsString(),
                MailCC = reader["MailCC"].AsString(),
                MailCode = reader["MailCode"].AsString(),
                MailTo = reader["MailTo"].AsString(),
                Note = reader["Note"].AsString(),
                Parameter = reader["Parameter"].AsString(),
                TitleEN = reader["TitleEN"].AsString(),
                TitleVN = reader["TitleVN"].AsString()
            };
    }
}
